package com.example.lcqexcel.jzjc.test;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.example.lcqexcel.jzjc.dto.DataDto;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.List;

public class MyDataListener extends AnalysisEventListener {
    private List<DataDto> resultList;

    public MyDataListener(){
        resultList = new ArrayList<>();
    }

    @Override
    public void invoke(Object o, AnalysisContext analysisContext) {
        resultList.add((DataDto) o);
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {
        System.out.println("数据读取完成");
        if (CollectionUtils.isEmpty(resultList)){
            System.out.println("没有数据！！");
            return;
        }

        resultList.forEach(data->{
            System.out.println(data.getResult());
        });
    }
}
